﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
using Cosmetic.DataEntity;

public partial class Controls_BrandSeriesTest : System.Web.UI.Page
{
	ProductSeriesManager m_SeriesManager = new ProductSeriesManager();
	BrandManager m_BrandManager	= new BrandManager();
	protected void Page_Load(object sender, EventArgs e)
	{
		
		this.BrandSeries3.SelectedBrand		= m_BrandManager.GetAll()[1];

		//ProductSeriesManager theSeriesManager	= new ProductSeriesManager();
		//this.BrandSeries4.SelectedSeries	= theSeriesManager.GetProductSeriesByBrand(BrandSeries3.SelectedBrand)[1];

		this.BrandDropDownList1.SelectedBrandChanged	+=new Controls_BrandDropDownList.SelectedBrandChangedHandler(this.SeriesDropDownList1.BrandChanged);
	}

	protected void Page_LoadComplete(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			Brand theBrand								= this.m_BrandManager.GetBrandById(new Guid("fa13831d-a3a9-439c-8888-9593744f157d"));
			ProductSeries theSeries						= theBrand.ProductSeries[2];
			this.BrandDropDownList1.SelectedBrand		= theSeries.Brand;
			this.SeriesDropDownList1.SelectedSeries		= theSeries;
		}
	}

	protected void cbCreateSeries_CheckedChanged(object sender, EventArgs e)
	{
		if(this.cbCreateSeries.Checked)
		{
			this.ltlBrandOrSeries.Text	= "Series";
		}
		else
		{
			this.ltlBrandOrSeries.Text	= "Brand";
		}

		this.pnlBrand.Visible			= !this.pnlBrand.Visible;
		this.ddlBrand.SelectedBrand		= this.ddlBrandSeriesList.SelectedBrand;
	}

	protected void btnInsertBrandSeries_Click(object sender, EventArgs e)
	{
		if (String.IsNullOrEmpty(this.txtBrandSeriesName.Text.Trim()))
		{
			this.ltlNeedBrandSeriesName.Visible	= true;
			return;
		}
		else
		{
			this.ltlNeedBrandSeriesName.Visible	= false;
		}

		// create Series
		if (this.cbCreateSeries.Checked)
		{
			Brand theBrand					= this.ddlBrand.SelectedBrand;
			ProductSeries theNewSeries		= new ProductSeries();
			theNewSeries.ProductSeriesId	= Guid.NewGuid();
			theNewSeries.Name				= this.txtBrandSeriesName.Text.Trim();
			theNewSeries.CreateTime			= DateTime.Now;
            theNewSeries.BrandId = theBrand.BrandId;
			this.m_SeriesManager.Insert(theNewSeries);
			this.ddlBrandSeriesList.SelectedSeries		= theNewSeries;
		}
		// create brand
		else
		{
			Brand theNewBrand			= new Brand();
			theNewBrand.BrandId			= Guid.NewGuid();
			theNewBrand.EnglishName		= this.txtBrandSeriesName.Text.Trim();
			theNewBrand.ChineseName		= theNewBrand.EnglishName;
			theNewBrand.CreateTime		= DateTime.Now;
			this.m_BrandManager.Insert(theNewBrand);
			this.ddlBrandSeriesList.SelectedBrand		= theNewBrand;
		}
	}
}
